<template>
  <div>
    <FormPanel ref="topFilter" :list="topFilterList" :isSubmitBtn="false"></FormPanel>
    <el-row>
      <el-col :span="24">
        <BreakSpace label="调拨单明细" :containerStyle="{ marginBottom: '20px' }"></BreakSpace>
        <div class="grid-content bg-purple">
          <FilterTable
            height="auto"
            ref="table"
            columnsRef="allocationItemsRef"
            :columns="columns"
            :fetchapi="fetchapi"
            :params="fetchParams"
            :datakey="'rows'"
            :onSyncTableData="handleSyncTableData"
            :onColumnsChange="columns => (this.columns = columns)"
          >
          </FilterTable>
        </div>
      </el-col>
      <el-col :span="24">
        <BreakSpace label="审核记录" :containerStyle="{ marginBottom: '20px' }"></BreakSpace>
        <div class="grid-content bg-purple">
          <FilterTable
            height="auto"
            ref="table1"
            columnsRef="allocationItemsRef1"
            :columns="columns1"
            :fetchapi="fetchapi1"
            :params="fetchParams1"
            :datakey="'rows'"
            :onSyncTableData="handleSyncTableData"
            :onColumnsChange="columns => (this.columns = columns)"
          >
          </FilterTable>
        </div>
      </el-col>
    </el-row>

    <div class="btnWrap">
      <el-button @click="closeDrawer(1)">关 闭</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { queryPrePay, getAllUser } from '@/api/finance/advancesReceived/registerQuery';
import {
  newBuild,
  getpartStocksList,
  getDealertCode,
  getfindStorageCode,
  getquerypartGroupCodes,
  getpartInfos,
  querypartInfo,
  getStockQuantity,
  getPosition,
  savePartInfo,
  save,
  queryUsableLocations
} from '@/api/part/inventoryManager/inventoryManager/index';
import { queryAllocationOut, queryAllocationOutItems, getExaminedLogs } from '@/api/part/allocation';
import { confirmAction, notifyAction } from '@/utils';

export default {
  mixins: [dictionary],
  props: {
    data: Object
  },
  data() {
    return {
      topFilterList: this.createTopFIlterList(),
      columns: this.createTableColumns(),
      columns1: this.createTableColumns1(),
      fetchapi1: getExaminedLogs,
      fetchParams1: { xhrAbort: true },
      fetchapi: queryAllocationOutItems,
      fetchParams: { xhrAbort: true },
      showPanel: false,
      syncTableData: [] // 同步的table数据
    };
  },

  mounted() {
    this.getAllUser();
    this.topFilterList.find(x => x.fieldName == 'orderStatus').itemList = this.createDictList('9031');
    this.getStorage();
    this.init();
  },
  methods: {
    createTableColumns1() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '审核日期',
          dataIndex: 'createdAt',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd',
          showOverflowTooltip: true
        },
        {
          title: '审核人',
          dataIndex: 'createdBy',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '审核状态',
          dataIndex: 'orderStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('9031'),
          dictItems: this.createDictList('9031'),
          showOverflowTooltip: true
        },
        {
          title: '审核意见',
          dataIndex: 'examinedRemark',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        }
      ];
    },
    createTopFIlterList() {
      return [
        {
          type: 'INPUT',
          label: '出库单号',
          disabled: true,
          fieldName: 'allocateOutNo'
        },
        {
          type: 'SELECT',
          label: '对方经销商',
          fieldName: 'customerCode',
          disabled: true,
          itemList: [
            { text: 'ARCFOX体验中心', value: 'AF1102S' },
            { text: '北汽新能源三里屯ARCFOX SPACE体验中心', value: 'AF0101S' }
          ]
        },
        {
          type: 'INPUT',
          label: '对应单据号',
          disabled: true,
          fieldName: 'allocateInNo'
        },
        {
          type: 'SELECT',
          label: '申请人',
          disabled: true,
          fieldName: 'handler',
          itemList: []
        },
        {
          type: 'INPUT',
          label: '申请人电话',
          disabled: true,
          fieldName: 'handlerPhone'
        },
        {
          type: 'DATE',
          label: '申请日期',
          fieldName: 'orderDate',
          disabled: true,
          valueFormat: 'yyyy-MM-dd'
        },
        {
          type: 'INPUT',
          label: '申请备注',
          disabled: true,
          fieldName: 'remark'
        },
        {
          type: 'SELECT',
          label: '调拨状态',
          fieldName: 'orderStatus',
          disabled: true,
          itemList: []
        },
        {
          type: 'DATE',
          label: '审核日期',
          fieldName: 'examinedDate',
          disabled: true,
          valueFormat: 'yyyy-MM-dd'
        },
        {
          type: 'TEXT_AREA',
          label: '审核备注',
          fieldName: 'examinedRemark',
          disabled: true
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '仓库名称',
          dataIndex: 'storageCode',
          dictItems: [],
          filterType: 'checkbox',
          sorter: true
        },
        {
          title: '库位',
          dataIndex: 'storagePositionCode',
          sorter: true
        },
        {
          title: '配件代码',
          dataIndex: 'partNo',
          sorter: true
        },
        {
          title: '配件名称',
          dataIndex: 'partName',
          sorter: true
        },
        {
          title: '可用库存',
          filterType: 'number',
          dataIndex: 'usableStock',
          precision: 2,
          sorter: true
        },
        {
          title: '调拨数量',
          dataIndex: 'outQuantity',
          sorter: true,
          precision: 2,
          filter: true,
          filterType: 'number',
          min: 0,
          max: Infinity
        },
        {
          title: '调拨单价',
          filterType: 'number',
          dataIndex: 'outPrice',
          precision: 2,
          sorter: true
        },
        {
          title: '调拨金额',
          filterType: 'number',
          precision: 2,
          dataIndex: 'outAmount',
          initialValue: 0,
          sorter: true
        },
        {
          title: '成本价',
          filterType: 'number',
          dataIndex: 'costPrice',
          precision: 2,
          sorter: true
        }
      ];
    },
    collapseHandle() {
      this.nextTick(() => {
        this.refs.table.EXECUTE_RESET_HEIGHT();
      });
    },
    async closeDrawer(val) {
      if (val == 1) {
        this.$emit('close', false);
      }
    },
    init() {
      console.log(this.data, 'this.data::');
      this.topFilterList.find(x => {
        x.initialValue = this.data[x.fieldName];
      });
      this.fetchParams = Object.assign({ allocateOutNo: this.data.allocateOutNo });
      this.fetchParams1 = Object.assign({ allocateOutNo: this.data.allocateOutNo });
    },
    // 点击搜索
    handleSearch() {},
    async getAllUser() {
      let res = await getAllUser();
      this.topFilterList.find(x => x.fieldName == 'handler').itemList = res.data.map(x => ({ text: x.employeeName, value: x.userId }));
    },
    async getStorage() {
      const res = await getfindStorageCode();
      this.columns.find(item => item.dataIndex === 'storageCode').dictItems = res.data.map(x => ({ text: x.STORAGE_NAME, value: x.STORAGE_CODE }));
      // this.form[0].itemList = res.data.map(x => ({ text: x.STORAGE_NAME, value: x.STORAGE_CODE }));
    },
    // 同步table数据
    handleSyncTableData(list) {
      this.syncTableData = list;
    }
  }
};
</script>

<style lang="less" scoped>
.btnWrap {
  position: absolute;
  left: 0px;
  bottom: 0px;
  right: 0px;
  z-index: 9;
  border-top: 1px solid rgb(233, 233, 233);
  padding: 10px 20px;
  background: rgb(255, 255, 255);
  text-align: right;
}
</style>
